package com.network.action;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import com.network.cfg.Configuration;
import com.network.entity.User;
import com.network.entity.UserQryHelper;
import com.network.service.IUserService;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

@Component
public class UserAction extends ActionSupport {
	
//	public static final String NETWORK_FLAG_KEY = "networkFlagKey";
//	public static final String CURVE_FLAG_KEY = "curveFlagKey";
	public static final String BA_FLAG = "baFlag";
	public static final String BBV_FLAG = "bbvFlag";
	public static final String ER_FLAG = "erFlag";
	public static final String SWB_FLAG = "swbFlag";
	public static final String WS_FLAG = "wsFlag";
	
	public static final String AVG_DEGREE_FLAG = "avgDegreeFlag";
	public static final String CRUEL_FLAG = "cruelFlag";
	
	public static final String FILE_PATH = "filePath";
	

	
	private User user;
	
	private String password;
	
	private IUserService userService;
	
	private String networkFlag;
	
	private String curveFlag;
	
	public String gotoEmulation()
	{
		return SUCCESS;
	}
	
	public String gotoSocialNetwork()
	{
		return SUCCESS;
	}
	
	public String gotoModifyInfo()
	{
		user = (User) ActionContext.getContext().getSession().get(Configuration.USER);
		 
		return SUCCESS;
	}
	
	public String modifyUserInfo()
	{
		userService.saveOrUpdateUser(user);
		ActionContext.getContext().put(Configuration.USER_RETURN_MSG, "用户信息修改成功！");
		return SUCCESS;
	}
	
	public String showBA()
	{
		ActionContext.getContext().put(FILE_PATH, Configuration.NETWORK_TEMP_FILE_PATH+"a.json");

		return SUCCESS;
	}
	
	public String showER()
	{
		return SUCCESS;
	}
	
	public String showSWB()
	{
		return SUCCESS;
	}
	
	public String showWS()
	{
		return SUCCESS;
	}
	
	public String showBBV()
	{
		return SUCCESS;
	}
	
	public String showAvgDegree()
	{
		ActionContext.getContext().put(FILE_PATH, Configuration.CURVE_TEMP_FILE_PATH+"data.csv");
		return SUCCESS;
	}
	
	public String showCruel()
	{
		ActionContext.getContext().put(FILE_PATH, Configuration.CURVE_TEMP_FILE_PATH+"d1.csv");
		return SUCCESS;
	}
	
	public String showNetworkMax()
	{
		if(networkFlag == null)
		{
			//TODO:如果iframe中没有图形，则暂时默认在新窗口中打开BA页面
			return Configuration.GOTO_SHOW_BA;
		}
		else if(networkFlag.equals(BA_FLAG))
		{
			ActionContext.getContext().put(FILE_PATH, Configuration.NETWORK_TEMP_FILE_PATH+"a.json");
			return Configuration.GOTO_SHOW_BA; 
		}
		else if(networkFlag.equals(BBV_FLAG))
		{
			return Configuration.GOTO_SHOW_BBV; 
		}
		else if(networkFlag.equals(ER_FLAG))
		{
			return Configuration.GOTO_SHOW_ER; 
		}
		else if(networkFlag.equals(WS_FLAG))
		{
			return Configuration.GOTO_SHOW_WS; 
		}
		else if(networkFlag.equals(SWB_FLAG))
		{
			return Configuration.GOTO_SHOW_SWB; 
		}
		else
		{
			//TODO:如果标志位无效，则暂时默认在新窗口中打开BA页面
			return Configuration.GOTO_SHOW_BA;
		}
	}
	
	public String showCurveMax()
	{
		if(curveFlag == null)
		{
			//TODO:如果iframe中没有图形，则暂时默认在新窗口中打开BA页面
			return Configuration.GOTO_AVG_DEGREE;
		}
		else if(curveFlag.equals(AVG_DEGREE_FLAG))
		{
			ActionContext.getContext().put(FILE_PATH, Configuration.CURVE_TEMP_FILE_PATH+"data.csv");
			return Configuration.GOTO_AVG_DEGREE; 
		}
		else if(curveFlag.equals(CRUEL_FLAG))
		{
			ActionContext.getContext().put(FILE_PATH, Configuration.CURVE_TEMP_FILE_PATH+"d1.csv");
			return Configuration.GOTO_CRUEL; 
		}
		else
		{
			//TODO:如果标志位无效，则暂时默认在新窗口中打开BA页面
			return Configuration.GOTO_AVG_DEGREE;
		}
	}
	
	public String modifyPassword()
	{
		user = userService.getUserById(user.getUserName());
		user.setPassword(password);
		userService.saveOrUpdateUser(user);
		ActionContext.getContext().put(Configuration.USER_RETURN_MSG, "用户密码修改成功！");
		return SUCCESS;
	}
	
	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public IUserService getUserService() {
		return userService;
	}

	@Resource(name="userServiceImpl")
	public void setUserService(IUserService userService) {
		this.userService = userService;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getNetworkFlag() {
		return networkFlag;
	}

	public void setNetworkFlag(String networkFlag) {
		this.networkFlag = networkFlag;
	}

	public String getCurveFlag() {
		return curveFlag;
	}

	public void setCurveFlag(String curveFlag) {
		this.curveFlag = curveFlag;
	}
	
	

}
